package cn.com.sinosoft.ares.common.util;

import java.security.MessageDigest;

/**
 * Description: MD5工具类
 * Author: lishangmin
 * Created: 2018-06-26 10:48
 */
public class MD5Util {

    /***
     * MD5加密 生成32位md5码
     * @param inStr 待加密字符串
     * @return 返回32位md5码
     */
    public static String md5Encode(String inStr) {
        MessageDigest md5 = null;
        byte[] byteArray;
        try {
            md5 = MessageDigest.getInstance("MD5");
            byteArray = inStr.getBytes("UTF-8");
        } catch (Exception e) {
            e.printStackTrace();
            return "";
        }
        byte[] md5Bytes = md5.digest(byteArray);
        StringBuilder hexValue = new StringBuilder();
        for (byte md5Byte : md5Bytes) {
            int val = ((int) md5Byte) & 0xff;
            if (val < 16) {
                hexValue.append("0");
            }
            hexValue.append(Integer.toHexString(val));
        }
        return hexValue.toString().toUpperCase();
    }

}
